home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / news / thor / rexx / tictactoe.thor < prev    next >
Text File  |  1998-05-24  |  11KB  |  519 lines

  1. /* TicTacToe.thor by Troels Walsted Hansen (some additional stuff by Sigbjørn Skjæret)
  2. ** $VER: TicTacToe.thor 1.12 (30.5.95)
  3. **
  4. ** Play TicTacToe!
  5. **
  6. ** Tons of code ripped from:
  7. ** 'TicTacSpot v1.0 © 1993 PSR Software'
  8. */
  9.  
  10. TEMPDIR = 'T:'
  11.  
  12. /* needs THOR and bbsread.library functions */
  13.  
  14. options results
  15.  
  16. p = ' ' || address() || ' ' || show('P',,)
  17. thorport = pos(' THOR.',p)
  18.  
  19. if thorport > 0 then thorport = word(substr(p,thorport+1),1)
  20. else
  21. do
  22.     say 'No THOR port found!'
  23.     exit 10
  24. end
  25.  
  26. if ~show('p', 'BBSREAD') then
  27. do
  28.     address command
  29.         "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  30.         "WaitForPort BBSREAD"
  31. end
  32.  
  33. /* start of script */
  34.  
  35. address(thorport)
  36. SAVEMESSAGE CURRENT FILENAME '"' || TEMPDIR || 'TicTacToe.thor.temp' || '"' NOHEADER NOANSI
  37.  
  38. if ~Open('Inp',TEMPDIR'TicTacToe.thor.temp','r') then
  39. do
  40.    REQUESTNOTIFY TEXT '"Cannot open temporary file: ' || TEMPDIR || 'TicTacToe.thor.temp"' BT '"_Ok"'
  41.    exit
  42. end
  43.  
  44. do y=1 to 4
  45.    do x=1 to 3
  46.       POS.x.y=' '
  47.    end
  48. end
  49.  
  50. newgame = 0
  51.  
  52. do until pos('* TicTacToe',LINE)>0
  53.    If Eof('Inp') Then Do
  54.       REQUESTNOTIFY TEXT '"Message contains no TicTacToe data!"' BT '"_Ok"'
  55.       REQUESTNOTIFY TEXT '"Start new game?"' BT '"_Yes|_No"'
  56.       if(rc=0 & result = 1) then do
  57.         newgame = 1
  58.         call close('Inp')
  59.         signal PlayMove
  60.       end
  61.       exit
  62.    end
  63.    if exists('Ram:Plop') then exit
  64.    LINE=readln('Inp')
  65. end
  66.  
  67. call readln('Inp')
  68. LINE.1=readln('Inp')
  69. call readln('Inp')
  70. call readln('Inp')
  71. LINE.2=readln('Inp')
  72. call readln('Inp')
  73. call readln('Inp')
  74. LINE.3=readln('Inp')
  75. call readln('Inp')
  76. call readln('Inp')
  77. xplayer = substr(readln('Inp'), 7)
  78. oplayer = substr(readln('Inp'), 7)
  79.  
  80. call close('Inp')
  81.  
  82. do y=1 to 3
  83.   parse var LINE.y POS1' | 'POS2' | 'POS3
  84.   POS1=right(POS1,2)
  85.   POS2=left(POS2,2)
  86.   POS3=left(POS3,2)
  87.   if POS1='/\' then POS.1.y='o'
  88.   if POS1='\/' then POS.1.y='x'
  89.   if POS2='/\' then POS.2.y='o'
  90.   if POS2='\/' then POS.2.y='x'
  91.   if POS3='/\' then POS.3.y='o'
  92.   if POS3='\/' then POS.3.y='x'
  93. end
  94.  
  95. PlayMove:
  96.  
  97.     address(thorport)
  98.     CURRENTBBS stem CURRENT
  99.     if(rc ~= 0) then
  100.     do
  101.         address(thorport)
  102.         REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
  103.         signal exit
  104.     end
  105.  
  106.     address(bbsread)
  107.     GETBBSDATA bbsname '"'CURRENT.BBSNAME'"' stem BBSDATA
  108.     if(rc ~= 0) then
  109.     do
  110.         address(thorport)
  111.         REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  112.         signal exit
  113.     end
  114.  
  115.     if(BBSDATA.USERNAME = '') then
  116.     do
  117.         GETGLOBALDATA stem GLOBALDATA
  118.             if(rc ~= 0) then
  119.             do
  120.                 address(thorport)
  121.                 REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  122.                 signal exit
  123.             end
  124.  
  125.         if(GLOBALDATA.USERNAME = '') then signal exit
  126.         else username = GLOBALDATA.USERNAME
  127.     end
  128.     else username = BBSDATA.USERNAME
  129.  
  130.     if(newgame) then xplayer = username
  131.  
  132.     select
  133.         when(username = oplayer) then
  134.         do
  135.             PIECE = 'o'
  136.         end
  137.  
  138.         when(username = xplayer) then
  139.         do
  140.             PIECE = 'x'
  141.         end
  142.  
  143.         otherwise signal exit
  144.     end
  145.  
  146. address(thorport)
  147.  
  148. DONE=0
  149.  
  150. do until DONE=1
  151.   BOARD=POS.1.1 || '|' || POS.2.1 || '|' || POS.3.1 || '\n' || POS.1.2 || '[' || POS.2.2 || ']' || POS.3.2 || '\n' || POS.1.3 || '|' || POS.2.3 || '|' || POS.3.3
  152.   REQUESTNOTIFY TEXT '"' || 'Top Row:\n' || board || '"' BT '"t_L|t_M|t_R|_Next|_Cancel"'
  153.   if result=0 then exit
  154.   if result=1 then if POS.1.1=' ' then do
  155.     DONE=1
  156.     POS.1.1=PIECE
  157.   end
  158.   if result=2 then if POS.2.1=' ' then do
  159.     DONE=1
  160.     POS.2.1=PIECE
  161.   end
  162.   if result=3 then if POS.3.1=' ' then do
  163.     DONE=1
  164.     POS.3.1=PIECE
  165.   end
  166.   if result=4 then do until DONE=1|result=4
  167.     REQUESTNOTIFY TEXT '"' || 'Middle Row:\n' || board || '"' BT '"m_L|m_M|m_R|_Next|_Cancel"'
  168.     if result=0 then exit
  169.     if result=1 then if POS.1.2=' ' then do
  170.       DONE=1
  171.       POS.1.2=PIECE
  172.     end
  173.     if result=2 then if POS.2.2=' ' then do
  174.       DONE=1
  175.       POS.2.2=PIECE
  176.     end
  177.     if result=3 then if POS.3.2=' ' then do
  178.       DONE=1
  179.       POS.3.2=PIECE
  180.     end
  181.     if result=4 then do until DONE=1|result=4
  182.       REQUESTNOTIFY TEXT '"' || 'Bottom Row:\n' || board || '"' BT '"b_L|b_M|b_R|_Next|_Cancel"'
  183.       if result=0 then exit
  184.       if result=1 then if POS.1.3=' ' then do
  185.         DONE=1
  186.         POS.1.3=PIECE
  187.       end
  188.       if result=2 then if POS.2.3=' ' then do
  189.         DONE=1
  190.         POS.2.3=PIECE
  191.       end
  192.       if result=3 then if POS.3.3=' ' then Do
  193.         DONE=1
  194.         POS.3.3=PIECE
  195.       end
  196.     end
  197.   end
  198. end
  199.  
  200. if(newgame) then
  201. do
  202.     EVENT.TYPE = 0 /* entermsg */
  203.  
  204.     address(bbsread)
  205.     GETBBSLIST stem BBSLIST
  206.     if(rc ~= 0) then
  207.     do
  208.         address(thorport)
  209.         REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  210.         exit 5
  211.     end
  212.  
  213.     address(thorport)
  214.     REQUESTLIST instem BBSLIST title '"Select BBS:"' SIZEGADGET
  215.     if(rc ~= 0) then exit
  216.     else MSG.BBSNAME = result
  217.  
  218.     address(bbsread)
  219.         GETCONFLIST '"'MSG.BBSNAME'"' CONFLIST
  220.     if(rc ~= 0) then
  221.     do
  222.         address(thorport)
  223.         REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  224.         exit 5
  225.     end
  226.  
  227.     address(thorport)
  228.  
  229.     REQUESTLIST instem CONFLIST title '"Select conf:"' SIZEGADGET
  230.     if(rc ~= 0) then exit
  231.     else EVENT.CONFERENCE = result
  232.  
  233.     REQUESTSTRING TITLE '"Please enter subject of message:"' BT '"_Ok|_Cancel"' ID '"TicTacToe"' MAXCHARS 100
  234.     EVENT.SUBJECT = result
  235.     if(rc ~= 0 | EVENT.SUBJECT = "") then exit
  236.  
  237.     do forever
  238.         REQUESTSTRING TITLE '"Please enter the name of your opponent:"' BT '"_Ok|_Cancel "' MAXCHARS 200
  239.         if(rc ~= 0) then signal exit
  240.         EVENT.TONAME = result
  241.  
  242.         if(upper(EVENT.TONAME) ~= "ALL") then
  243.         do
  244.             address(bbsread)
  245.             SEARCHBRUSER bbsname '"'MSG.BBSNAME'"' stem USERS search '"'EVENT.TONAME'"' name address alias suggestusersstem SUG
  246.             if(rc ~= 0) then signal exit
  247.  
  248.             if(result > 0) then
  249.             do
  250.                 drop LIST.
  251.                 drop USERTAGS.
  252.  
  253.                 LIST.COUNT = USERS.COUNT
  254.  
  255.                 do n = 1 to USERS.COUNT
  256.                     LIST.n.USERNR = USERS.n.USERNR
  257.  
  258.                     address(bbsread)
  259.                     READBRUSER bbsname '"'MSG.BBSNAME'"' usernr USERS.n.USERNR tagsstem USERTAGS
  260.                     if(rc ~= 0) then signal exit
  261.                     LIST.n = USERTAGS.NAME
  262.  
  263.                     if(symbol("USERTAGS.ADDRESS") = "VAR") then
  264.                         LIST.n.ADDRESS = USERTAGS.ADDRESS
  265.                 end
  266.  
  267.                 address(thorport)
  268.                 REQUESTLIST instem LIST title '"Select user:"'
  269.                 if(rc ~= 0) then
  270.                 do
  271.                     if(rc ~= 5) then REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
  272.                     signal exit
  273.                 end
  274.  
  275.                 EVENT.TONAME = result
  276.  
  277.                 do n = 1 to LIST.COUNT
  278.                     if(LIST.n = EVENT.TONAME) then
  279.                         EVENT.TOADDR = LIST.n.ADDRESS
  280.                 end
  281.                 leave
  282.             end
  283.             else
  284.             do
  285.                 if(symbol("SUG.COUNT") = "VAR") then do
  286.                     address(thorport)
  287.                     REQUESTLIST instem SUG title '"Select user:"'
  288.                     if(rc ~= 0) then
  289.                     do
  290.                         if(rc ~= 5) then REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
  291.                         signal exit
  292.                     end
  293.  
  294.                     EVENT.TONAME = result
  295.  
  296.                     do n = 1 to SUG.COUNT
  297.                         if(SUG.n = EVENT.TONAME) then
  298.                             usernumber = SUG.n.USERNR
  299.                     end
  300.  
  301.                     drop USERTAGS.
  302.  
  303.                     address(bbsread)
  304.                     READBRUSER bbsname '"'MSG.BBSNAME'"' usernr usernumber tagsstem USERTAGS
  305.                     if(rc ~= 0) then signal exit
  306.  
  307.                     if(symbol("USERTAGS.ADDRESS") = "VAR") then
  308.                         EVENT.TOADDR = USERTAGS.ADDRESS
  309.  
  310.                     leave
  311.                 end
  312.                 else
  313.                 do
  314.                     address(thorport)
  315.                     REQUESTNOTIFY TEXT '"No matching users found, try again?"' BT '"_Ok|_Cancel"'
  316.                     if(rc ~= 0) then signal exit
  317.                     if(result = 0) then signal exit
  318.                 end
  319.             end
  320.         end
  321.         else signal exit /* doesn't work with ALL */
  322.     end
  323.  
  324.     oplayer = EVENT.TONAME
  325. end
  326. else
  327. do
  328.     CURRENTMSG stem MSG
  329.  
  330.     address(bbsread)
  331.     READBRMESSAGE bbsname '"'MSG.BBSNAME'"' confname '"'MSG.CONFNAME'"' msgnr '"'MSG.MSGNR'"' headstem HEAD textstem TEXT
  332.  
  333.     EVENT.TYPE = 1 /* replymsg */
  334.     EVENT.TONAME = HEAD.FROMNAME
  335.     EVENT.SUBJECT = HEAD.SUBJECT
  336.     EVENT.CONFERENCE = MSG.CONFNAME
  337.     EVENT.REFNR = MSG.MSGNR
  338.     EVENT.REFORGINALNR = HEAD.ORGINALNR
  339.     /*EVENT.REFID = HEAD.REFID*/
  340.     /*EVENT.TOADDR = TEXT.REPLYADDR*/
  341. end
  342.  
  343. call open('Oup',TEMPDIR'TicTacToe.thor.temp','w')
  344.  
  345. LINE1=' >  '
  346. LINE2=' >  '
  347. LINE3=' >  '
  348. LINE4=' >  '
  349. LINE5=' >  '
  350. LINE6=' >  '
  351. If POS.1.1='x' Then Do
  352.   LINE1=LINE1||'\/ |'
  353.   LINE2=LINE2||'/\ |'
  354. End
  355. If POS.1.1='o' Then Do
  356.   LINE1=LINE1||'/\ |'
  357.   LINE2=LINE2||'\/ |'
  358. End
  359. If POS.1.1=' ' Then Do
  360.   LINE1=LINE1||'   |'
  361.   LINE2=LINE2||'   |'
  362. End
  363. If POS.2.1='x' Then Do
  364.   LINE1=LINE1||' \/ |'
  365.   LINE2=LINE2||' /\ |'
  366. End
  367. If POS.2.1='o' Then Do
  368.   LINE1=LINE1||' /\ |'
  369.   LINE2=LINE2||' \/ |'
  370. End
  371. If POS.2.1=' ' Then Do
  372.   LINE1=LINE1||'    |'
  373.   LINE2=LINE2||'    |'
  374. End
  375. If POS.3.1='x' Then Do
  376.   LINE1=LINE1||' \/'
  377.   LINE2=LINE2||' /\'
  378. End
  379. If POS.3.1='o' Then Do
  380.   LINE1=LINE1||' /\'
  381.   LINE2=LINE2||' \/'
  382. End
  383.  
  384. If POS.1.2='x' Then Do
  385.   LINE3=LINE3||'\/ |'
  386.   LINE4=LINE4||'/\ |'
  387. End
  388. If POS.1.2='o' Then Do
  389.   LINE3=LINE3||'/\ |'
  390.   LINE4=LINE4||'\/ |'
  391. End
  392. If POS.1.2=' ' Then Do
  393.   LINE3=LINE3||'   |'
  394.   LINE4=LINE4||'   |'
  395. End
  396. If POS.2.2='x' Then Do
  397.   LINE3=LINE3||' \/ |'
  398.   LINE4=LINE4||' /\ |'
  399. End
  400. If POS.2.2='o' Then Do
  401.   LINE3=LINE3||' /\ |'
  402.   LINE4=LINE4||' \/ |'
  403. End
  404. If POS.2.2=' ' Then Do
  405.   LINE3=LINE3||'    |'
  406.   LINE4=LINE4||'    |'
  407. End
  408. If POS.3.2='x' Then Do
  409.   LINE3=LINE3||' \/'
  410.   LINE4=LINE4||' /\'
  411. End
  412. If POS.3.2='o' Then Do
  413.   LINE3=LINE3||' /\'
  414.   LINE4=LINE4||' \/'
  415. End
  416.  
  417. If POS.1.3='x' Then Do
  418.   LINE5=LINE5||'\/ |'
  419.   LINE6=LINE6||'/\ |'
  420. End
  421. If POS.1.3='o' Then Do
  422.   LINE5=LINE5||'/\ |'
  423.   LINE6=LINE6||'\/ |'
  424. End
  425. If POS.1.3=' ' Then Do
  426.   LINE5=LINE5||'   |'
  427.   LINE6=LINE6||'   |'
  428. End
  429. If POS.2.3='x' Then Do
  430.   LINE5=LINE5||' \/ |'
  431.   LINE6=LINE6||' /\ |'
  432. End
  433. If POS.2.3='o' Then Do
  434.   LINE5=LINE5||' /\ |'
  435.   LINE6=LINE6||' \/ |'
  436. End
  437. If POS.2.3=' ' Then Do
  438.   LINE5=LINE5||'    |'
  439.   LINE6=LINE6||'    |'
  440. End
  441. If POS.3.3='x' Then Do
  442.   LINE5=LINE5||' \/'
  443.   LINE6=LINE6||' /\'
  444. End
  445. If POS.3.3='o' Then Do
  446.   LINE5=LINE5||' /\'
  447.   LINE6=LINE6||' \/'
  448. End
  449.  
  450.   call writeln('Oup',' ')
  451.   call writeln('Oup',' > * TicTacToe')
  452.   call writeln('Oup',' >')
  453.   call writeln('Oup',LINE1)
  454.   call writeln('Oup',LINE2)
  455.   call writeln('Oup',' > ----+----+----')
  456.   call writeln('Oup',LINE3)
  457.   call writeln('Oup',LINE4)
  458.   call writeln('Oup',' > ----+----+----')
  459.   call writeln('Oup',LINE5)
  460.   call writeln('Oup',LINE6)
  461.   call writeln('Oup',' >')
  462.   call writeln('Oup',' > X: 'xplayer)
  463.   call writeln('Oup',' > O: 'oplayer)
  464.   call writeln('Oup',' ')
  465.  
  466. call close('Oup')
  467.  
  468. address(bbsread)
  469. UNIQUEMSGFILE bbsname '"'MSG.BBSNAME'"' stem UNIQUEFILE
  470. if(rc ~= 0) then
  471. do
  472.     address(thorport)
  473.     REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  474.     exit
  475. end
  476.  
  477. address command 'copy >nil: ' || TEMPDIR || 'TicTacToe.thor.temp' || ' TO ' || UNIQUEFILE.NAME
  478. EVENT.MSGFILE = UNIQUEFILE.FILEPART
  479.  
  480. address(bbsread)
  481. WRITEBREVENT bbsname '"'MSG.BBSNAME'"' event EVENT.TYPE stem EVENT
  482. if(rc ~= 0) then
  483. do
  484.     address(thorport)
  485.     REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  486.     exit 5
  487. end
  488.  
  489. address(thorport)
  490. SHOWTEXT TEMPDIR'TicTacToe.thor.temp'
  491.  
  492. address command 'delete >nil: ' || TEMPDIR || 'TicTacToe.thor.temp'
  493.  
  494. address(thorport)
  495. REQUESTNOTIFY TEXT '"Edit message?"' BT '"_Yes|_No"'
  496. if(result=1) then STARTEDITOR FILE '"'UNIQUEFILE.NAME'"'
  497.  
  498. exit
  499.  
  500. /*
  501.  > * TicTacToe
  502.  >
  503.  >  \/ | /\ | \/
  504.  >  /\ | \/ | /\
  505.  > ----+----+----
  506.  >  \/ | /\ | \/
  507.  >  /\ | \/ | /\
  508.  > ----+----+----
  509.  >  \/ | /\ | \/
  510.  >  /\ | \/ | /\
  511.  >
  512.  > X: Sigbjørn Skjæret
  513.  > O: Troels Walsted_Hansen
  514. */
  515.  
  516. signal exit:
  517.     address command 'delete' TEMPDIR'TicTacToe.thor.temp quiet'
  518.     exit
  519.